//
//  MCStatusForwardCell.swift
//  HXWeibo
//
//  Created by HX on 15/12/6.
//  Copyright © 2015年 HX. All rights reserved.
//

import UIKit

/// 转发cell
class MCStatusForwardCell: MCStatusCell
{
    // 子类覆盖父类的属性 需要
    // 1.添加 override 关键字
    override var status: MCStatus?
        {// 2.实现属性监视器 (先调父类的属性监视器，再调子类的属性监视器)
            didSet
            {
                // 设置被转发微博的内容
                let name = status?.retweeted_status?.user?.screen_name ?? "被转发微博名称为空"
                
                let retweetText = status?.retweeted_status?.text ?? "被转发微博内容为空"
                
                let text = "@" + name + ":" + retweetText
                
                forwardLabel.text = text
                
            }
        }
    
    // 覆盖父类的方法
    override func prepareUI()
    {
        super.prepareUI()
        
//        contentView.addSubview(bgBtn)
        // 添加之类自己特有的控件， atIndex:0 是插入到最底部
        contentView.insertSubview(bgBtn, atIndex: 0)
        contentView.addSubview(forwardLabel)
        
        //设置约束
        bgBtn.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: contentLabel, size: nil, offset: CGPoint(x: -MCStatusCellMargin, y: MCStatusCellMargin))
        bgBtn.ff_AlignVertical(type: ff_AlignType.TopRight, referView: bottomView, size: nil, offset: CGPoint(x: 0, y: 0))
        
        forwardLabel.ff_AlignInner(type: ff_AlignType.TopLeft, referView: bgBtn, size: nil, offset: CGPoint(x: MCStatusCellMargin, y: MCStatusCellMargin))
        contentView.addConstraint(NSLayoutConstraint(item: forwardLabel, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: UIScreen.mainScreen().bounds.size.width - 2 * MCStatusCellMargin))
        
        /// 配图视图约束
        let cons = pictureView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: forwardLabel, size: CGSize(width: 290, height: 290), offset: CGPoint(x: 0, y: MCStatusCellMargin))
        
        // 获取配图视图的宽高约束
        pictureViewWidth = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Width)
        pictureViewHeight = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Height)
        
    }

    // MARK: - 懒加载
    // 背景 按钮
    private lazy var bgBtn: UIButton =
    {
        let btn = UIButton()
        
        btn.backgroundColor = UIColor(white: 0.8, alpha: 1)
        
        return btn
    }()
    
    // label 显示被转发微博的内容
    private lazy var forwardLabel: UILabel =
    {
        let label = UILabel(color: UIColor.lightGrayColor(), fontSize: 14)
        
        label.numberOfLines = 0
        
        return label
    }()
}



































